package business.command
{
	import business.event.GetUserByUserIdEvent;
	import business.event.RegisterUserEvent;
	import business.service.delegate.BusinessAMDelegate;
	
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import mx.controls.Alert;
	import mx.rpc.IResponder;
	
	import valueObjects.User;
	
	public class RegisterUserCommand implements ICommand, IResponder
	{
		public function RegisterUserCommand()
		{
		}
		public function execute(event:CairngormEvent):void {
			regeisterUser = (event as RegisterUserEvent).registerUser;
			var businessAM:BusinessAMDelegate = new BusinessAMDelegate(this);
			businessAM.registerUser(regeisterUser);
		}
		public function result(result:Object):void {
			isRegistered = result.result as Boolean;
			if(isRegistered){
				var getUserEvent:GetUserByUserIdEvent = new GetUserByUserIdEvent();
				getUserEvent.userId = regeisterUser.userId;
				getUserEvent.dispatch();
				Alert.show("Successfully Registered! Already Logged In!");
			}
		}
		public function fault(info:Object):void {
			
		}
		private var regeisterUser:User;
		private var isRegistered:Boolean = false;

	}
}